import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules ,longLimtVal} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {UploadTypeEnum} from "/@/components/Form/src/jeecg/components/JUpload";
import {defHttp} from '/@/utils/http/axios';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '风险类型',
    align:"center",
    dataIndex: 'risktype'
  },
  {
    title: '督查时间',
    align:"center",
    dataIndex: 'checktime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
  },
   {
    title: '企业名称',
    align:"center",
    dataIndex: 'enterprisename'
   },
   {
    title: '企业地址',
    align:"center",
    dataIndex: 'address'
   },
   {
    title: '企业负责人',
    align:"center",
    dataIndex: 'dutyperson'
   },
   {
    title: '负责人手机',
    align:"center",
    dataIndex: 'dutypersonphone'
   },
   {
    title: '企业联系人',
    align:"center",
    dataIndex: 'connectperson'
   },
   {
    title: '联系人手机',
    align:"center",
    dataIndex: 'connectphone'
   },
   {
    title: '是否分租',
    align:"center",
    dataIndex: 'positionstatus'
   },
   {
    title: '占地面积',
    align:"center",
    dataIndex: 'landsize'
   },
   {
    title: '建筑面积',
    align:"center",
    dataIndex: 'buildingsize'
   },
   {
    title: '安全生产培训演练',
    align:"center",
    dataIndex: 'exercise'
   },


/*   {
    title: '有限空间',
    align:"center",
    dataIndex: 'limitspace'
   },
   {
    title: '珍珠棉',
    align:"center",
    dataIndex: 'cotton'
   },
   {
    title: '锂电池',
    align:"center",
    dataIndex: 'libattery'
   },
   {
    title: '再生资源',
    align:"center",
    dataIndex: 'renew'
   },
   {
    title: '粉尘涉爆',
    align:"center",
    dataIndex: 'dust'
   },
   {
    title: '危化品',
    align:"center",
    dataIndex: 'chemistry'
   },
   {
    title: '物流存储',
    align:"center",
    dataIndex: 'store'
   },
   {
    title: '其他',
    align:"center",
    dataIndex: 'other'
   },*/
   {
    title: '实地督查意见',
    align:"center",
    dataIndex: 'advice'
   },
   {
    title: '督查人',
    align:"center",
    dataIndex: 'adviceperson_dictText'
   },
   {
    title: '企业签名盖章',
    align:"center",
    dataIndex: 'sign',
    slots: { customRender: 'signSlot' },
   },
   {
    title: '备注',
    align:"center",
    dataIndex: 'remark'
   },

];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "企业名称",
      field: 'enterprisename',
      component: 'JInput',
      colProps: {span: 6},
 	},
     {
      label: "督查时间",
      field: "checktime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
      },
      colProps: {span: 6},
	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '督查时间',
    field: 'checktime',
    component: 'DatePicker',
    componentProps:{
      showToday:true,
      valueFormat:'YYYY-MM-DD'
    },
    defaultValue:new Date(),
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入督查时间!'},
      ];
    },
  },
  {
    label: '企业名称',
    field: 'enterprisename',
    component: 'JSearchSelect',
    // component: 'Input',
/*    componentProps:{
      dict:"DB_QYZLB,MC,MC",
      async:true,
      pageSize:10,
    },*/
    componentProps:({formModel})=>{
      return {
        // isRadioSelection:true
        dict:"DB_QYZLB,MC,MC",
        async:true,
        pageSize:10,
        onChange: (e: ChangeEvent) => {
          defHttp.get({url: '/assets.enterprise/dbQyzlb/list', params:{
            mc: `*${e}*`
          }}).then(res=>{
            console.log(res);
            if(res.records.length){
              let obj = res.records[0]
              formModel.address = obj.dz
              formModel.connectperson = obj.lxr
              formModel.connectphone = obj.dh
              formModel.risktype = obj.risktype
            }
          })
        },
      }
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入企业名称!'},
      ];
    },
  },
  {
    label: '企业地址',
    field: 'address',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,50)
          },
        },
      ];
    },
  },
  {
    label: '企业负责人',
    field: 'dutyperson',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '负责人手机',
    field: 'dutypersonphone',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '企业联系人',
    field: 'connectperson',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '联系人手机',
    field: 'connectphone',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '场地情况',
    field: 'positionstatus',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '占地面积',
    field: 'landsize',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },
  {
    label: '建筑面积',
    field: 'buildingsize',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { 
          validator: (_, value) => {
            return longLimtVal(value,16)
          },
        },
      ];
    },
  },

  {
    label: '安全生产培训演练状况',
    field: 'exercise',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:'check_certificate_state'
    }
  },

  {
    label: '风险类型',
    field: 'risktype',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:'risk_type'
    }
  },

/*  {
    label: '有限空间',
    field: 'limitspace',
    component: 'InputNumber',
  },
  {
    label: '珍珠棉',
    field: 'cotton',
    component: 'InputNumber',
  },
  {
    label: '锂电池',
    field: 'libattery',
    component: 'InputNumber',
  },
  {
    label: '再生资源',
    field: 'renew',
    component: 'InputNumber',
  },
  {
    label: '粉尘涉爆',
    field: 'dust',
    component: 'InputNumber',
  },
  {
    label: '危化品',
    field: 'chemistry',
    component: 'InputNumber',
  },
  {
    label: '物流存储',
    field: 'store',
    component: 'InputNumber',
  },
  {
    label: '其他',
    field: 'other',
    component: 'InputNumber',
  },*/
  {
    label: '实地督查意见',
    field: 'advice',
    component: 'InputTextArea',
    defaultValue:"通过",
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入实地督查意见!'},
      ];
    },
  },
  {
    label: '督查人',
    field: 'adviceperson',
    component: 'JSelectUser',
    componentProps:{
      labelKey:'realname',
      rowKey:'id',
      isRadioSelection:false,
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入督查人!'},
      ];
    },
  },
  {
    label: '企业签名盖章',
    field: 'sign',
    component: 'JUpload',
    componentProps: { fileType: UploadTypeEnum.image,maxCount: 5 },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },

  {
    field: 'picpath',
    component: 'JUpload',
    label: '督查图片',
    helpMessage: '最多上传10个图片',
    componentProps: { fileType: UploadTypeEnum.image,maxCount: 10 },
  },
  {
    label: '是否需要重检',
    field: 'needrecheck',
    component: 'JSwitch',
    componentProps:({formModel})=>{
      return{
        options:['是','否'],
        onChange: () => {
          formModel.recheckdate = ''
        },
      }
    },
  },
  {
    label: '重检时间',
    field: 'recheckdate',
    component: 'DatePicker',
    show:({values})=> {
        return values.needrecheck=='是'
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
